package com.shengyuan.manage_os.old.ying.erpm.db;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;

public class Actual_ErpUser extends DBHelper {

	private String Table = "ERPUSER";
	private String sql;
	public String UserName="UserName", UserPwd="UserPwd", Department="Department", JiaoSe="JiaoSe", 
			IfLogin ="IfLogin", JiaTingDianHua ="JiaTingDianHua";
	public long ID;
	public Actual_ErpUser(Context ctx) {
		super(ctx);
		open();
		boolean condition = isTableExist(Table);
		if (!condition) {
			sql = "CREATE TABLE "
					+ Table
					+ "(ID INTEGER, UserName VARCHAR, UserPwd VARCHAR,Department VARCHAR, JiaoSe VARCHAR, IfLogin VARCHAR, JiaTingDianHua VARCHAR )";
			execSQL(sql);
		}
	}
	
//	public void Update(String jixiename, String starttime, int id) {
//		String sql = "UPDATE " + Table 
//				+ " SET " + STATE + " = 1, " + STARTTOEND + "= '" +  starttime +"', ID=" + id 
//				+ " WHERE "+ JIXIENAME +"='" + jixiename + "'";
//		mDb.execSQL(sql ) ;
//	}
//	
//	public int getState(String name) {
//		String sql = "SELECT "+ STATE +" FROM " + Table 
//				+ " WHERE " + JIXIENAME + "='"+ name +"'";
//		int state = GetValue(sql);
//		return state;
//	}
//
//	public String getTime(String name) {
//		String sql = "SELECT " + STARTTOEND + " FROM " + Table 
//				+ " WHERE " + JIXIENAME + "='"+ name +"'";
//		String result = GetString(sql);
//		return result;
//	}
	public void DeleteData( String User) {
		String sql="Delete FROM " + Table  + " WHERE " + UserName + "='" + User + "'";
		this.execSQL(sql);
	}
	
	public int GetRowsCount() {
		String sql="SELECT COUNT(*) FROM " + Table ;
		int count = GetValue(sql);
		return count;
	}
	
	public String getField(String Field,  String User) {
	String sql = "SELECT " +  Field + " FROM " + Table 
			+ " WHERE " + UserName + "='"+ User +"'";
	//int state = GetString(sql);
	return GetString(sql);
}
	
	public void Insert_Row() {
		String sql ="INSERT INTO " + Table + 
					" (ID, UserName, UserPwd, Department, JiaoSe, IfLogin, JiaTingDianHua)" + 
					" VALUES(" + ID +", '"+ UserName +"','"+ UserPwd +"','"+ Department +"','"+ JiaoSe+"', '"+ IfLogin +"', '"+ JiaTingDianHua +"')";
		mDb.execSQL(sql);
	}
	
	public ArrayList<String> getAllUserName() {
	ArrayList<String> list = new ArrayList<String>();
	Cursor cursor = findList(Table, new String[]{UserName},null, 
			null,null, null, null  );
	while (cursor.moveToNext()) {
		String s = cursor.getString(0);
		list.add(s);
	}
	return list;
}
	/*
	 * finished=0 完成一半工作 
	 * finished=1 全部完成
	 */
//	private Cursor List_Finished(int finished, String form_type) {
//		return findList(Table_actual_form, new String[]{JSON1}, 
//				"sended=0 and finished=? and user=? and form_type=?", 
//				new String[]{finished+"", LoginActivity.pmUser.v_yhdm, form_type},null, null, null  );
//	}
//	
//	
//	public ArrayList<String> getArray_Finished(int finished, String form_type) {
//		ArrayList<String> list = new ArrayList<String>();
//		Cursor cursor = List_Finished(finished, form_type);
//		while (cursor.moveToNext()) {
//			String s = cursor.getString(0);
//			list.add(s);
//		}
//		return list;
//	}
	
}
